const axios = require("axios");

const checkIn = async (cookie) => {
    return axios({
        method: 'post',
        url: 'https://glados.rocks/api/user/checkin',
        data: {
            token: "glados_network"
        },
        headers: {
          cookie
        }
    })
}

const status = async (cookie) => {
    return axios({
        method: 'get',
        url: 'https://glados.rocks/api/user/status',
        headers: {
          cookie
        }
    })
}

const server = (checkInMessage, leftDays) => {
    return axios({
        method: 'get',
        url: `https://sc.ftqq.com/${SCKEY}.send`,
        params: {
            text: `${leftDays}天后到期，${checkInMessage}`
        }
    })
}

const GLaDOSCheckIn = async (cookie) => {
    const checkInMessage = (await checkIn(cookie))?.data?.message;
    const statusData = (await status(cookie))?.data?.data
    const leftDays = parseInt(statusData?.leftDays);
    console.log(statusData, leftDays, checkInMessage);
    if (SCKEY) {
        server(checkInMessage, leftDays);
    }
}

const SCKEY = process.env.SCKEY;
const COOKIES = process.env.COOKIES;
const cookiesList = COOKIES.split('koa:sess=eyJ1c2VySWQiOjI5OTg0MCwiX2V4cGlyZSI6MTcwNTA2ODM2ODIyMiwiX21heEFnZSI6MjU5MjAwMDAwMDB9; koa:sess.sig=HafViMSsenoxVjieUky81WH0Va8; Cookie=enabled; Cookie.sig=lbtpENsrE0x6riM8PFTvoh9nepc; _gid=GA1.2.1652714276.1679473478; _gat_gtag_UA_104464600_2=1; _ga=GA1.1.1275089980.1679148186; _ga_CZFVKMNT9J=GS1.1.1679473477.5.1.1679474787.0.0.0--分隔符--')

cookiesList.forEach(cookie=>{
  GLaDOSCheckIn(cookie);
})
